package org.qtproject;
import org.qtproject.qt.android.bindings.QtActivity;
import java.lang.String;
import java.util.List;
import java.util.ArrayList;
import android.Manifest;
import android.content.pm.PackageManager;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.content.Context;
import android.app.Activity;
import android.content.Intent;
import org.qtproject.qt.android.QtNative;
import android.provider.Settings;
import android.view.WindowManager;
import android.os.Handler;
import android.os.Looper;

public class QtAndroid extends org.qtproject.qt.android.bindings.QtActivity{
    private static List<String> mPermissionList = new ArrayList<>();
    static Activity qtActivity = QtNative.activity();   // 获取qt的activity
    private static Handler mainHandler;
    static {
        mainHandler = new Handler(Looper.getMainLooper());
    }
    // 权限添加
    public static void AddPermission(String str_permission){
        if (ContextCompat.checkSelfPermission(qtActivity, str_permission) != PackageManager.PERMISSION_GRANTED) {
            mPermissionList.add(str_permission);
        }
    }
    // 权限申请
    public static void ApplyPermission(){
        if (mPermissionList.isEmpty()) {
            //未授予的权限为空，表示都授予了
        } else {
            String[] permissions = mPermissionList.toArray(new String[mPermissionList.size()]);//将List转为数组
            ActivityCompat.requestPermissions(qtActivity, permissions, 1);  //请求权限方法
        }
        mPermissionList.clear();
    }
    public static void EnableInput(){
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                qtActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
            }
        });
    }
    public static void DisableInput(){
        // 在UI线程更新UI
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                qtActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
            }
        });

    }
    // 测试例子
    public static int test2(int num){
        return num + 2;
    }
}
